<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
Object obj=request.getSession().getAttribute("role_resource");
if(null==obj){
	response.setStatus(1000);
	return;
}
%> 
		<script type="text/javascript">
	//账单列表数据源
	var p1_store = new Ext.data.JsonStore( {
		root : "data",
		totalProperty : "total",
		fields : [ "period","compose_type","filename", "compose_share","compose_page","paper_no","paper_name"
		,"businpnt_no","businpnt_name","card_id","card_name","start_time","end_time","state"],
		url : "work!sampleComposeLog.action"
	});
	//账单状态下拉列表
	var state_store = new Ext.data.JsonStore( {
		fields : ["id","text"],
		data:[{id:"",text:"全部"},{id:"0",text:"生成失败"},{id:"1",text:"生成成功"},{id:"2",text:"生成中"},{id:"3",text:""}]
	});
	//卡产品下拉列表
	var card_store = new Ext.data.JsonStore( {
		root: "data",
		fields : ["prodId","prodName"],
		url: "product!ProdName.action",
		listeners : {
				"load": function() {
					var RecordName = Ext.data.Record.create([
						{name: "prodId"},
						{name: "prodName"}
					]);
					var newRecord = new RecordName({
						prodName: "全部"
					});
					this.insert(0,newRecord);
				}
			}
	});
	//性别下拉列表
	var sex_store = new Ext.data.JsonStore({
		fields : ["id","text"],
		data : [{id:"",text:"全部"},{id:"F",text:"女"},{id:"M",text:"男"}]
	});
	//积分类型下拉列表
	var point_type = new Ext.data.JsonStore({
		fields : ["id","text"],
		data : [{id:"",text:"全部"},{id:"0",text:"无积分"},{id:"1",text:"仅携程积分"},{id:"2",text:"仅万里通积分"},{id:"3",text:"两者都有"}]
	});
	//单双币标识
	var curr_type = new Ext.data.JsonStore({
		fields : ["id","text"],
		data : [{id:"",text:"全部"},{id:"0",text:"仅人民币"},{id:"1",text:"仅美元"},{id:"2",text:"两者都有"}]
	});
	//人民币自扣标识;//人民币自扣标识：1:有自扣，需还款，2:有自扣，无需还款，3:无自扣，需还款，4:无自扣，无需还款
	var rmbpayflag_store = new Ext.data.JsonStore({
		fields : ["id","text"],
		data : [{id:"",text:"全部"},{id:"1",text:"有自扣，需还款"},{id:"2",text:"有自扣，无需还款"},{id:"3",text:"无自扣，需还款"},{id:"4",text:"无自扣，无需还款"}]
	});
	//美元自扣标识
	var usdpayflag_store = new Ext.data.JsonStore({
		fields : ["id","text"],
		data : [{id:"",text:"全部"},{id:"1",text:"有自扣，需还款"},{id:"2",text:"有自扣，无需还款"},{id:"3",text:"无自扣，需还款"},{id:"4",text:"无自扣，无需还款"}]
	});
	//借记交易标识
	var jjflag_store = new Ext.data.JsonStore({
		fields : ["id","text"],
		data : [{id:"",text:"全部"},{id:"0",text:"无交易"},{id:"1",text:"有交易"}]
	});
	//催收标识
	var cycledue_store = new Ext.data.JsonStore({
		fields : ["id","text"],
		data : [{id:"",text:"全部"},{id:"0",text:"无催收"},{id:"1",text:"有催收"}]
	});
	//汇购类型
	var exch_type = new Ext.data.JsonStore({
		fields : ["id","text"],
		data : [{id:"",text:"全部"},{id:"0",text:"无汇购"},{id:"1",text:"有汇购"}]
	});
	//账单类型
	var card_type=new Ext.data.JsonStore( {
		fields : ["id","text"],
		data:[{id:"",text:"全部"},{id:"1",text:"纸质"},{id:"2",text:"电子"}]
	});

	//抽样纸质相关的数据源
	var paperwin;
	var pdfdata=new Ext.data.JsonStore({
		totalProperty: 50,
		fields: ["f","strIndex"]
	});
	//选择素材
	var selectPDF = {
		id: "selectPDF",
		xtype: "grid",
		stripeRows: true,
		store: pdfdata,
		headersDisabled: true,
		columns:[
	    		new Ext.grid.RowNumberer(),
	    		{header: "账户号",		dataIndex: "strIndex", menuDisabled: true},
				{header: "pdf文件",		dataIndex: "f",width:550, menuDisabled: true}
		]
	};
	//抽样电子相关的数据源
	var elecwin;
	var pdfdataE_store=new Ext.data.JsonStore({
		root: 'data',
		totalProperty: 50,
		fields: ["HTMLpath"],
		url: 'work!sample.action'
	});
	//选择HTML路径
	var selectPDF_E = {
		id: "selectPDF_E",
		xtype: "grid",
		stripeRows: true,
		store: pdfdataE_store,
		headersDisabled: true,
		columns:[
	    		new Ext.grid.RowNumberer(),
	    		{header: "HTML路径",		dataIndex: "HTMLpath",width:550, menuDisabled: true}
		],
		bbar: new Ext.ux.PagingToolbar( {
			pageSize : limit,
			store : pdfdataE_store
		})
	};

	var check_select = new Ext.grid.CheckboxSelectionModel();
	var samlped_pel = new Ext.Panel( {
		id: "rule_panel",
		border : false, 
		layout: "card",
		activeItem:0,
		items:[{
			id: "rule_grid",
			xtype:"grid",
			store:p1_store,
			autoExpandColumn: "filename",
			autoExpandMin: 100,
			headersDisabled: true,
			selModel : new Ext.grid.RowSelectionModel(),
			columns:[
				new Ext.grid.RowNumberer( {header : "序号",width : 30}), 
				//check_select,
			    {dataIndex : "period",header : "期别", menuDisabled: true},
			    {dataIndex : "compose_type",header : "类别", menuDisabled: true,
				   renderer:function(input){
	 				  if(""==input)return input;
	          		  var res2=card_type.getById(input);
					  return res2.data.text;
	           	   }
			    },
			    {dataIndex : "filename",header : "文件名称", id:"filename", menuDisabled: true},
			    {dataIndex : "compose_share",header : "账单份数", menuDisabled: true},
			    {dataIndex : "compose_page",	header : "账单页数", menuDisabled: true},
			    {dataIndex : "paper_name",header : "预印纸名称", menuDisabled: true},
			    {dataIndex : "businpnt_name",header : " 外包商 ", menuDisabled: true},
			    {dataIndex : "card_name",header : " 卡产名称 ", menuDisabled: true},
			    {dataIndex : "start_time",header : "开始时间", menuDisabled: true},
			    {dataIndex : "end_time",header : "结束时间", menuDisabled: true},          
			    {dataIndex :"state",header:"状态", menuDisabled: true,
			       renderer:function(input){
	 				  if(""==input)return input;
	 				  if(input>2){input = 3;};
	          		  var res3=state_store.getById(input);
					  return res3.data.text;
	           	   }
			    }
			],
			buttonAlign: "center",
			tbar:[{
				xtype: "buttongroup",
				columns: 2,
				defaults:{
					scale: "small"
				},
				items:	[{
					    xtype: "label",
					    text: "账单状态"
					},{
						id: "selectstate",
						text: "查询条件",
						xtype: "billCombox",
						width: 100,
						store: 	state_store,
						emptyText: "全部",
						listeners: {
							"select": function(){
								p1_store.load({params:{start:0,limit:limit,"logdata.state": this.value}});
							}
						}
					},{
					    xtype: "label",
					    text: "卡产品"
					},{
						id: "selectcardid",
						xtype: "billCombox",
						width: 100,
						store: 	card_store,
						emptyText: "全部",
						valueField: "prodId",
						displayField: "prodName",
						listeners : {
								"select": function() {
										p1_store.load({params:{start:0,limit:limit,"logdata.card_id": this.value}});
								}
						}							
					},{
						xtype: "label",
						text: "账单类型"
					},{
						id: "selecttype",
						xtype: "billCombox",
						width: 100,
						store: card_type,
						valueField: "id",
						displayField: "text",
						emptyText: "全部",
						listeners : {
							"select": function() {
									p1_store.load({params:{start:0,limit:limit,"logdata.compose_type": this.value}});
							}
					}
					}]
				},{
					xtype: "buttongroup",
					columns: 2,
					defaults:{
						scale: "small"
					},
					items:	[{
						xtype: "label",
						text: "生日"
					},{
						id : "birthday",
						width:"100",
						name : "birthday",
						xtype:"datefield",format:"Y-m-d",
						editable :true
					},{
						xtype: "label",
						text: "固定额度"
					},{
						id : "crlim",
						width:"100",
						name : "crlim",
						xtype:"numberfield"
					},{
						xtype: "label",
						text: "积分类型"
					},{
						id: "pointtype",
						xtype: "billCombox",
						width: 100,
						store: point_type,
						emptyText: "全部",
						valueField: "id",
						displayField: "text"
					}]
				},{
					xtype: "buttongroup",
					columns: 2,
					defaults:{
						scale: "small"
					},
					items:	[{
						xtype: "label",
						text: "单双币标识"
					},{
						id: "currtype",
						xtype: "billCombox",
						width: 100,
						store: curr_type,
						emptyText: "全部",
						valueField: "id",
						displayField: "text"
					},{
						xtype: "label",
						text: "人民币自扣标识"
					},{
						id: "rmbpayflag",
						xtype: "billCombox",
						width: 100,
						store: rmbpayflag_store,
						emptyText: "全部",
						valueField: "id",
						displayField: "text"
					},{
						xtype: "label",
						text: "美元自扣标识"
					},{
						id: "usdpayflag",
						xtype: "billCombox",
						width: 100,
						store: usdpayflag_store,
						emptyText: "全部",
						valueField: "id",
						displayField: "text"
					}]
				},{
					xtype: "buttongroup",
					columns: 2,
					defaults:{
						scale: "small"
					},
					items:[{
						xtype: "label",
						text: "借记交易标识"
					},{
						id: "jjflag",
						xtype: "billCombox",
						width: 100,
						store: jjflag_store,
						emptyText: "全部",
						valueField: "id",
						displayField: "text"
					},{
						xtype: "label",
						text: "催收标识"
					},{
						id: "cycledue",
						xtype: "billCombox",
						width: 100,
						store: cycledue_store,
						emptyText: "全部",
						valueField: "id",
						displayField: "text"
					},{
						xtype: "label",
						text: "汇购类型"
					},{
						id: "exchtype",
						xtype: "billCombox",
						width: 100,
						store: exch_type,
						emptyText: "全部",
						valueField: "id",
						displayField: "text"
					}]
			},{
				xtype: "buttongroup",
				columns: 2,
				defaults:{
					scale: "small"
				},
				items:[{
					xtype: "label",
					text: "模板编号"
				},{
					id: "stencil_no",
					xtype: "textfield",
					width: 100,
					validator: function(val) {
						if(Ext.fucCheckCHLength(val)>8){
							return '请输入8个以内字符(包含8个)！';
						}
						var pat=new RegExp("[^a-zA-Z0-9]","i");
						if(pat.test(val)) {
							return '此项只能输入数字和字母！';
						}
						return true;
					}
				},{
					xtype: "label",
					text: "模板版本号"
				},{
					id: "versino",
					xtype: "numberfield",
					width: 100
				},{
					xtype: "label",
					text: "性别"
				},{
					id: "selectsex",
					xtype: "billCombox",
					width: 100,
					store: sex_store,
					emptyText: "全部",
					valueField: "id",
					displayField: "text"
				}]
		},{
			xtype:"buttongroup",
			columns: 2,
			defaults: { scale: "small"},
			items:[
				{
					xtype: "label",
					text: "城市"
				},{
					id: "city",
					xtype: "textfield",
					width: 88,
					maxLength: 4,
					emptyText:"请输入城市区号",
					validator: function(val){
						if((/^[\d]{1,4}$/).test(val) || ""==val){
							return true;
						}else{
							return "城市区号必须为数字！";
						}
					}
				}]
		}],
			bbar : new Ext.ux.PagingToolbar( {
				pageSize : 13,
				store:p1_store
			}),
			buttons: [{
				id: 'sampleButton',
				text: "抽样",
				handler: function(){
					var records = Ext.getCmp("rule_grid").getSelectionModel().getSelections();
					if(records.join("")==""){
						Ext.Msg.alert("提示","请选择一列数据再进行抽样！");
						return false;
					}
					Ext.Msg.confirm("提示","确定抽样吗?",function(button) {
						if(button == "yes") {
							Ext.getCmp("sampleButton").setDisabled(true);
							var state = records[0].data.state;
							if(state==1){
							//var ids = [];
							//for(var i = 0; i < records[0].data.length; i++){
							//	var member = records[i].get("period")+"|";
							//	member+=records[i].get("compose_type")+"|";
							//	member+=records[i].get("filename");
							//	ids.push(member);
							//}
								var birth;
								if (Ext.getCmp('birthday').getValue()){
									birth = Ext.getCmp('birthday').getValue().format('Ymd');
								}
								if(records[0].data.compose_type==1) {
									//调用纸质的抽样数据
									Ext.Ajax.request({
										params: {
											'billp.city':Ext.getCmp('city').getValue(),
											'billp.sex':Ext.getCmp('selectsex').getValue(),
											'billp.crlim':Ext.getCmp('crlim').getValue(),
											'billp.stencil_no':Ext.getCmp('stencil_no').getValue(),
											'billp.versino':Ext.getCmp('versino').getValue(),
											'billp.birthday':birth,
											'billp.pointtype':Ext.getCmp('pointtype').getValue(),
											'billp.currtype':Ext.getCmp('currtype').getValue(),
											'billp.rmbpayflag':Ext.getCmp('rmbpayflag').getValue(),
											'billp.usdpayflag':Ext.getCmp('usdpayflag').getValue(),
											'billp.jjflag':Ext.getCmp('jjflag').getValue(),
											'billp.cycledue':Ext.getCmp('cycledue').getValue(),
											'billp.exchtype':Ext.getCmp('exchtype').getValue(),
											'billp.period':records[0].data.period,
											'billp.card_no':records[0].data.card_id,
											'billp.page':records[0].data.compose_page,
											'billp.paper_no':records[0].data.paper_no,
											'billp.businpnt_no':records[0].data.businpnt_no,
											'billp.filename':records[0].data.filename,
											'billType':records[0].data.compose_type,
											'start':0,'limit':50},
										url: 'work!sample.action',
										success: function(response, opts){
											var res=Ext.util.JSON.decode(response.responseText);
											if(typeof(res)=="string"){
												alert(res);
											}else if(res.data.length!=0){
												pdfdata.loadData(res.data,false);
												if (!paperwin) {
									       			paperwin = new Ext.Window({
											                layout:'fit',
											                width:800,
											                height:600,
											                closeAction:'hide',//设置窗体关闭方式
											                plain: true,
											                items:[selectPDF],
											                buttons: [{
											                    text:'浏览',
											                    handler: function(){
												                   	var paper=Ext.getCmp("selectPDF");
												                	if(!paper.getSelectionModel().getSelected()){
												                		 Ext.Msg.alert("提示","请选择PDF文件！");
												                		 return;
												                	}
												                	var pdfPath = paper.getSelectionModel().getSelections();
																	var url="work!showPDF.action?pdfPath="+pdfPath[0].data.f;
																	var name = pdfPath+"_window";
																	var winparams="height=650, width=500, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no";
																	if(Ext.isIE){
																		window.open(url);
																	}else{
																		window.open(url, name, winparams);
																	}
											                    }
											                },{
											                    text: '关闭',
											                    handler: function(){
											                        paperwin.hide();
											                    }
											                }]
											            });
										       	}
												Ext.getCmp("sampleButton").setDisabled(false);
												paperwin.show();
												var num = pdfdata.totalLength;
												var msg = '';
												if(num>50){
													msg = "纸质账单抽样的PDF记录一共"+num+"条，系统只显示前50条记录";
												}else{
													msg = "纸质账单抽样的PDF记录一共"+num+"条";
												}
												Ext.Msg.show({
													title: "提示",
													msg: msg,
													buttom: Ext.Msg.OK,
													icon: Ext.MessageBox.INFO
												});
											}else{
												Ext.Msg.alert("提示","没有可选的数据，请重新选择条件！");
											}		
										}
									});
								}else if(records[0].data.compose_type==2){
									//调用电子的抽样数据
									pdfdataE_store.baseParams = pdfdataE_store.baseParams || {};

									pdfdataE_store.baseParams['bille.city'] = Ext.getCmp('city').getValue();
									pdfdataE_store.baseParams['bille.sex'] = Ext.getCmp('selectsex').getValue();
									pdfdataE_store.baseParams['bille.crlim'] = Ext.getCmp('crlim').getValue();
									pdfdataE_store.baseParams['bille.stencil_no'] = Ext.getCmp('stencil_no').getValue();
									pdfdataE_store.baseParams['bille.version'] = Ext.getCmp('versino').getValue();
									pdfdataE_store.baseParams['bille.birthday'] = birth;
									pdfdataE_store.baseParams['bille.pointtype'] = Ext.getCmp('pointtype').getValue();
									pdfdataE_store.baseParams['bille.currtype'] = Ext.getCmp('currtype').getValue();
									pdfdataE_store.baseParams['bille.rmbpayflag'] = Ext.getCmp('rmbpayflag').getValue();
									pdfdataE_store.baseParams['bille.usdpayflag'] = Ext.getCmp('usdpayflag').getValue();
									pdfdataE_store.baseParams['bille.jjflag'] = Ext.getCmp('jjflag').getValue();
									pdfdataE_store.baseParams['bille.cycledue'] = Ext.getCmp('cycledue').getValue();
									pdfdataE_store.baseParams['bille.exchtype'] = Ext.getCmp('exchtype').getValue();
									pdfdataE_store.baseParams['bille.period'] = records[0].data.period;
									pdfdataE_store.baseParams['bille.card_id'] = records[0].data.card_id;
									pdfdataE_store.baseParams['billType'] = records[0].data.compose_type;
									
									pdfdataE_store.load({params:{start:0,limit:50},callback:function (){
										if(pdfdataE_store){
											if (!elecwin) {
												elecwin = new Ext.Window({
										                layout:"fit",
										                width:800,
										                height:600,
										                closeAction:"hide",
										                plain: true,
										                items:[selectPDF_E],
										                buttons: [{
										                    text:"浏览",
										                    handler: function(){
											                   	var paper=Ext.getCmp("selectPDF_E");
											                	if(!paper.getSelectionModel().getSelected()){
											                		 Ext.Msg.alert("提示","请选择HTML文件！");
											                		 return;
											                	}
											                	var pdfPath = paper.getSelectionModel().getSelections();
																var url = "work!showPDF.action?pdfPath="+pdfPath[0].data.HTMLpath;
																var name = pdfPath+"_window";
																var winparams="height=500, width=400, top=0, left=0, scrollbars=yes, toolbar=no, menubar=no,resizable=no,location=no, status=no";
																if(navigator.userAgent.indexOf("MSIE")>0){
																	window.open(url);
																}else{
																	window.open(url, name, winparams);
																}
										                    }
										                },{
										                    text: "关闭",
										                    handler: function(){
										                    	elecwin.hide();
										                    }
										                }]
										            });
									       	}
											Ext.getCmp("sampleButton").setDisabled(false);
											elecwin.show();
											var num = pdfdataE_store.totalLength;
											var msg = '';
											if(num>50){
												msg = "电子账单抽样的HTML记录一共"+num+"条，系统只显示前50条记录";
											}else{
												msg = "电子账单抽样的HTML记录一共"+num+"条";
											}
											Ext.Msg.show({
												title: "提示",
												msg: msg,
												buttom: Ext.Msg.OK,
												icon: Ext.MessageBox.INFO
											});
										}else{
											Ext.Msg.alert("没有可选的数据，请重新选择条件！");
										}
									}
									});				
								}						
							}else{
								Ext.Msg.show({
									title: "提示",
									msg: "账单还未生成不能抽样",
									buttom: Ext.Msg.OK,
									icon: Ext.MessageBox.ERROR
								});
							}
						}
					});
				}
			}]
		}]
	});
	p1_store.load({params:{start:0,limit:limit}});
	card_store.load();
		
	var CenterPanel=Ext.getCmp("CenterPanel");
	CenterPanel.removeAll();
	CenterPanel.add(samlped_pel);
	CenterPanel.doLayout();
</script>